package acwing._1_1AlgorithmBasic._3SearchGraph;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._1_1AlgorithmBasic._3SearchGraph
 * @File : Q0842.java
 * @Author : WangRuoyu
 * @Date : 2023/4/1 10:42
 */

import java.io.*;

public class Q0842 {
    static int n;
    static int[] nums;
    static boolean[] st;

    static void dfs(int x, BufferedWriter wr) throws IOException {
        if (x == n) {
            for (int i = 0; i < nums.length; ++i) {
                wr.write(nums[i] + " ");
            }
            wr.write("\n");
        }
        for (int i = 0; i < n; ++i) {
            if (!st[i]) {
                st[i] = true;
                nums[x] = i + 1;
                dfs(x + 1, wr);
                st[i] = false;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] words = br.readLine().split(" ");
        n = Integer.parseInt(words[0]);
        nums = new int[n];
        st = new boolean[n];

        dfs(0, wr);

        wr.flush();
    }
}

